class CreateRoles < ActiveRecord::Migration
  def self.up
    create_table :roles do |t|
      t.string   "name",              :limit => 40, :null=>false
      t.string   "authorizable_type", :limit => 40
      t.integer  "authorizable_id"

      t.timestamps
    end
    
    add_index :roles, :name, :name=>"idx_name"
    
    create_table "roles_users", :id => false do |t|
      t.integer  "user_id", :null=>false
      t.integer  "role_id", :null=>false
      
      t.timestamps
    end

    add_index :roles_users, [:user_id, :role_id], :name=>"idx_role_user", :uniq=>true
  end

  def self.down
    drop_table :roles
    drop_table :roles_users
  end
end
